<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>编辑公海</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/formSelects-v4.css"/>
</head>
<style>

</style>
<body>
<div class="panel panel-default operation" >
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
            <input name="id" hidden/>
            <div class="layui-form-item">
                <label class="layui-form-label">公海名称</label>
                <div class="layui-input-block">
                    <input type="ghmc" name="ghmc" placeholder="请输入公海名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">公海管理员</label>
                <div class="layui-input-block">
                    <select id="ghglySC" name="ghgly" xm-select="select0" xm-select-show-count="3" xm-select-search="">
                        <option value="">请选择公海管理员</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">公海成员</label>
                <div class="layui-input-block">
                    <select id="ghcySC" name="ghcy" xm-select="select1" xm-select-show-count="3" xm-select-search="">
                        <option value="">请选择公海成员</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">公海成员部门</label>
                <div class="layui-input-block">
                    <select id="ghcybmSC" name="ghcybm" xm-select="select2" xm-select-show-count="3" xm-select-search="">
                        <option value="">请选择公海成员部门</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit" id="submit">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script th:inline="javascript"> var ghszIdVo =[[${ghszId}]]  </script>
<script src="/layui/layui.js" charset="utf-8"></script>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/home.js?v=0.1"></script>
<script src="/js/common.js"></script>
<script src="/layui/formSelects-v4.js"></script>
</body>
<script>
//获取token
var token = CoreUtil.getData("access_token");
//地址栏转义token中的#号
var tokenQuery = token.replace("#", "%23");
var tableIns1;
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
var $ = jQuery = layui.jquery;
var laydate = layui.laydate;
var upload = layui.upload;

var formSelects = layui.formSelects;

//全局定义一次, 加载formSelects
layui.config({
    base: '../src/' //此处路径请自行处理, 可以使用绝对路径
}).extend({
    formSelects: 'formSelects-v4'
});

info();
layui.use(['table', 'layer', 'laydate','form'], function () {
    //监听保存
    form.on('submit(submit)', function(data){
        data.field.id = ghszIdVo;
        CoreUtil.sendPut("/tGhsz/update",data.field,function (res) {
            parent.search();
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        });
    });
});

function info() {
    CoreUtil.sendGet("/tGhsz/infoData/", null, function (res) {
        var code = res.code;
        var datauser = res.data.user;
        var datadept = res.data.dept;
        if (code == 0) {
            //公海管理员
            //公海成员
            var keys = [];
            for (var i = 0; i < datauser.length; i++) {
                var temp = {
                    "name": datauser[i].username,
                    "value": datauser[i].id//这里需要注意，value应该不同
                }
                keys.push(temp)
            }
            var keydepts = [];
            for (var i = 0; i < datadept.length; i++) {
                var temp = {
                    "name": datadept[i].name,
                    "value": datadept[i].id//这里需要注意，value应该不同
                }
                keydepts.push(temp)
            }
            //公海管理员
            formSelects.data("select0", "local", {
                arr: keys
            });
            //公海成员
            formSelects.data("select1", "local", {
                arr: keys
            });
            //公海管理员部门
            formSelects.data("select2", "local", {
                arr: keydepts
            });
            form.render("select");
        }
        CoreUtil.sendPost("/tGhsz/infoDataById/"+ghszIdVo, null, function (res) {
            var code = res.code;
            var data = res.data;
            if (code == 0) {
                //给表单赋值
                form.val("info", {
                    ghmc: data.ghmc,
                    // ghgly: data.ghgly,
                });
                var keys0 =data.ghgly.split(",");
                var keys1 =data.ghcy.split(",");
                var keys2 =data.ghmc.split(",");
                // 公海管理员 公海成员
                formSelects.value('select0', keys0);
                formSelects.value('select1', keys1);
                formSelects.value('select2', keys2);
            }
        });
    });
};
</script>
</html>